package com.trs.publish.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.trs.publish.domain.Power;
import com.trs.publish.repository.PowerRepository;



/**
 * @author jia.haihong
 */
@Service
public class PowerService{

	@Autowired
    private PowerRepository powerRepository;

	public List<Power> getPowers(Long roleId) {
		return powerRepository.findPowers(roleId);
	}
	
	@Transactional
	public List<Power> getPowersByRoleNames(List<String> roleNameList) {
		List<Power> list = new ArrayList<Power>();
		if(roleNameList != null && roleNameList.size()>0){
			list = powerRepository.findPowersByRoles(roleNameList);
		}
		return list;
	}

	public List<Power> getList(Power power) {
		return powerRepository.findByPower(power);
	}
	
	@Transactional
	public void deletePower(long id) {
		powerRepository.delete(id);
	}

	public Power findById(long id) {
		return powerRepository.find(id);
	}
	
	@Transactional
	public void save(Power power) {
		powerRepository.save(power);
	}
	
	@Transactional
	public void update(Power power) {
		powerRepository.update(power);
	}
	
	public List<Power> getAllPowers(){
		return powerRepository.getAllPowers();
	}
	
	public List getRolesPowers(List list) {
		return powerRepository.getRolesPowers(list);
	}

}
